# coding:utf-8
# Author : hiicy redldw
# Date : 2019/06/14
# desc: 构造一幅图，遍历graph，两两点对应相连，输出所有连接点
class Graph(object):
    def __init__(self):
        self.G = {}
    def __setitem__(self, key, value):
        p1, p2 = key
        assert p1 != p2, 'pair shoulden\'t equality'
        # key = frozenset(key)
        # self.G[key] = value
        dict.__setitem__(self.G, key, value)
    def __getitem__(self, item):
        # item = frozenset(item)
        return self.G[item]
    def traverse(self):
        keys = [ k for k,v in self.G.items() if v is True]
        keys = sorted(keys,key=lambda j:j[0])
        print(keys)
        proposal = []
        def _traverse(curG:tuple,keys:list,proposal_:str):
            if len(keys) == 0:
                return proposal_
            v2 = curG[1]
            ci = -1
            for i,key in enumerate(keys):
                if v2 == key[0]:
                    ci = i
                    break
            if ci != -1:
                curG = keys.pop(ci)
                proposal_ += "->" + str(curG[1])
                proposal_=_traverse(curG,keys,proposal_)
            # print(proposal_)
            return proposal_
        while len(keys) != 0:
            curG = keys.pop(0)
            t = str(curG[0]) + "->" + str(curG[1])
            proposal.append(_traverse(curG,keys,t))

        print(proposal)





g = Graph()
g[0,3] = True
g[3,7] = True
g[7,11]= True
g[6,10] = True
g[10,12] = True
g[8,13] = True
g[9,14] = True
g[5,16] = True
g[16,17] = True
g.traverse()